package com.loongtech.bi.manager.player;

import com.loongtech.bi.entity.player.EntityNotIdfaDau;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NotIdfaDauManager extends ManagerQueryCacheBase<EntityNotIdfaDau> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间，返回所有在这两个时间之间的单日DAU对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaDau> getDauByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityNotIdfaDau where 1=1 and startday>=:dayStart and endday<=:dayEnd and startday=endday order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据开始结束时间，返回所有在这两个时间之间的所有DAU对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaDau> getAllDauByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityNotIdfaDau where 1=1 and startday=:dayStart and endday=:dayEnd order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据开始结束时间，返回所有在这两个时间之间的所有DAU对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaDau> getAllDauByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("from EntityNotIdfaDau where 1=1 and startday=:dayStart and endday=:dayEnd  and platformid=:platformid and channelid=:channelid and serverid=:serverid order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd), "platformid", queryPlatform, "channelid", queryChannel, "serverid", queryServer);
	}
	
	/**
	 * 根据开始结束时间和平台渠道区服条件，返回所有在这两个时间之间的单日DAU对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaDau> getDauByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("from EntityNotIdfaDau where 1=1 and startday>=:dayStart and endday<=:dayEnd and startday=endday and platformid=:platformid and channelid=:channelid and serverid=:serverid order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd), "platformid", queryPlatform, "channelid", queryChannel, "serverid", queryServer);
	}
	
	/**
	 * 根据platformid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getDauGroupByPlatform(Date dateStart, Date dateEnd) {
		return findByQuery("select platformid,sum(dau) from EntityNotIdfaDau where startday=:dayStart and endday=:dayEnd and platformid != '0' and dau is not null group by platformid", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据channelid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getDauGroupByChannel(Date dateStart, Date dateEnd) {
		return findByQuery("select channelid,sum(dau) from EntityNotIdfaDau where startday=:dayStart and endday=:dayEnd and channelid != '0' and dau is not null group by channelid", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据serverid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getDauGroupByServer(Date dateStart, Date dateEnd) {
		return findByQuery("select serverid,sum(dau) from EntityNotIdfaDau where startday=:dayStart and endday=:dayEnd and serverid != '0' and dau is not null group by serverid", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
}
